<?php
namespace Home\Controller;
use Think\Controller;
class RegController extends CommonController {
    public function index(){


    	$question = D('Verify')->getRandOne();

    	$this->assign('question',$question);

      $this->assign('title','注册');

      	$this->display();  
    }
    public function checkdata(){

      	$data = I('post.');

      	$vercode = I('post.vercode');

      	if($vercode!=$_SESSION['answer']){

      		$this->ajaxReturn(['error'=>1,'info'=>'人类验证不通过']);
      	}


      	$User = D("User"); // 实例化User对象

		if (!$User->create($data,1)){ // 指定新增数据
		     // 如果创建失败 表示验证没有通过 输出错误提示信息
		     // exit($User->getError());
		     $this->ajaxReturn(['error'=>1,'info'=>$User->getError()]);
		}else{

			$data['password'] = md5($data['password']); 

			$data['ctime'] =time();

			$res = M("User")->add($data);

			if($res){
				$this->ajaxReturn(['error'=>0,'info'=>'注册成功']);
			}else{
				$this->ajaxReturn(['error'=>1,'info'=>'注册失败']);
			}

		}


    }

    public function code()
    {
    	$Verify = new \Think\Verify();
		$Verify->entry();
    }



}